﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Payton.WP7.Common.Model;
using Payton.WP7.Common;

namespace Payton.WP7.ViewModel
{
    public class CommentViewmodel : ViewModelBase<SNSComment>, IComparable<CommentViewmodel>
    {
        public CommentViewmodel()
        {
            this.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Item")
                {
                    InitImageUri();
                }
            };
        }

        public CommentViewmodel(SNSComment comment)
            : base(comment)
        {
            InitImageUri();
        }

        private void InitImageUri()
        {
            if (Item.User != null && !string.IsNullOrEmpty(Item.User.ProfileImageUrl))
            {
                FaceImageUri = new Uri(Item.User.ProfileImageUrl, UriKind.Absolute);
            }
        }

        Uri faceImageUri;

        public Uri FaceImageUri
        {
            get { return faceImageUri; }
            set
            {
                if (value != faceImageUri)
                {
                    faceImageUri = value;
                    RaisePropertyChanged(() => FaceImageUri);
                }
            }
        }

        public string StatusInfoText
        {
            get
            {
                var str = "";

                str = string.Format("{0} 来自 {1}", Converter.TimeToStringConverter.GetFromNow(Item.CreatedTime),Item.Source);
                
                return str;
            }
        }


        public int CompareTo(CommentViewmodel other)
        {
            return DateTime.Compare(Item.CreatedTime, other.Item.CreatedTime);
        }
    }
}
